<!DOCTYPE html>
<html>
  <head>
    <title>哈尔滨家家户户科技--登陆</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="stylesheet" href="__CUSTOMER__/css/login.pkg.css">
  </head>
  <body>
    
    <div class="g-hd">
      <div class="m-logo">
        <div class="row logo">
          <img src="__COMMON__/img/LOGO.576.123.png" width="250">
        </div>
      </div>
      <div class="m-line"></div>
    </div>
    
    
    <div class="g-bd">
      <div class="m-login">
        <div class="row row-tit">用户登录</div>
        <div class="row row-phone"><input type="text" name="phone" class="js_phone" placeholder="请输入您的注册手机号" maxlength="11" id="username"></div>
        <div class="row row-pin">
          <span class="block block-pin"><input type="text" class="js_code" name="code" placeholder="请输入您收到的验证码" id="pin" maxlength="6"></span>
          <span class="block block-get">
            <input type="button" value="获取验证码" id="u-get-btn" class="js_get_code">
          </span>
        </div>
        <div class="row row-btn">
          <button class="block" id="submit">点击登录</button>
        </div>
      </div>
    </div>
    
    
    <div class="g-ft">
      <div class="m-global">
        <include file="Public/base_copy" />
      </div>
    </div>
    
    
    <script type="text/javascript" src="http://activityfiles.oss-cn-hangzhou.aliyuncs.com/2015/09/14-16-35/55f686c931275.js"></script>
    <script src="__CUSTOMER__/js/login.pkg.js"></script>
    <script type="text/javascript">
    $(function(){
      var now_time = new Date().getTime();
      var change_time = 0;
      function getChangeTime(){
        var last_time = $.cookie("last_time");
        if(typeof(last_time) != "undefined"){
          if(last_time > 0){
              change_time = now_time - last_time
          }
          return change_time;
        }else{
          return 60001;
        }
      };

         var wait = 60;
         function  time(o){
           if (wait == 0) {
             wait = 60;
               o.removeAttribute("disabled");
               $("#u-get-btn").css("background","#ff4a01");
               o.value="获取验证码";
           } else {
               o.setAttribute("disabled", true);
               $("#u-get-btn").css("background","#aaaaaa");
               o.value="重新发送(" + wait + ")";
               wait--;
               setTimeout(function() {
                   time(o)
               },1000)};
         }
         var c_time =  getChangeTime();
         if(c_time < 60000){
            wait = 60 - parseInt(c_time/1000);
            time(document.getElementById("u-get-btn"));
         };
         $("#u-get-btn").click(function(){
           var phone = $.trim($('.js_phone').val());//手机号
           var pin = $.trim($('.js_code').val());//验证码
             if (phone == '') {
               noticeDialog('用户手机号不能为空');
               $("#username").focus();
               return false;
              }
              if (!/^1[3-8][0-9]{9}$/.test(phone)) {
                 noticeDialog('用户手机号格式不正确');
                 $("#username").focus();
                 return false;
               }
             $.post("{:U('Customer/getSms')}",{
               "phone" : $(".js_phone").val()
             },function(data){
               noticeDialog(data.info);
             },"json");
             //存发送短信时间
             $.cookie("last_time", new Date().getTime())
             time(document.getElementById("u-get-btn"));
           });
           //alert提示
             function noticeDialog(content){
              var d = dialog({
                 "title": "家家户户网提示您",
                 "width":"220",
                 "content":content
               }).showModal();
                setTimeout(function(){
                 d.remove().close();
               }, 2000);
               return false;
             };
          $("#submit").click(function () {
              var phone = $.trim($('#username').val());//手机号
              var pin = $.trim($('#pin').val());//验证码
              if (phone == '') {
                  noticeDialog('用户手机号不能为空');
                  $("#username").focus();
                  return false;
                }
                if (!/^1[3-8][0-9]{9}$/.test(phone)) {
                  noticeDialog('手机号格式不正确');
                    $("#username").focus();
                    return false;
                }
              if (pin == '') {
                noticeDialog('验证码不能为空');
                $("#pin").focus();
                  return false;
              }
              var json_data = {
                  "phone":phone,
                  "code" : pin
              };
              $.ajax({
                  url: "{:U('Customer/login')}",//请求URL
                  data:json_data,
                  type:'post',
                  dataType:'json',
                  beforeSend:function(){
                      $("#submit").attr("disabled","disabled");
                  },
                  success:function(data){
                    $("#submit").removeAttr("disabled");
                    if(data.status == 1){
                      window.location.href = data.url;
                    }else{
                      noticeDialog(data.info);
                    }
                    return false;

                  },
                  error:function(obj,status,text){
                  noticeDialog("系统繁忙");
                  }
              });
          });
          $("input").keydown(function(event) {
              $(".ui-popup-backdrop,.ui-dialog-grid").hide();
              setTimeout(function(){
                if (event.keyCode == "13") {
                  $("#submit").click();
                }
              }, 200 );
            });

            //判断浏览器是否支持placeholder属性
             supportPlaceholder='placeholder'in document.createElement('input'),
                     placeholder=function(input){
                         var text = input.attr('placeholder'),
                                 defaultValue = input.defaultValue;
                         if(!defaultValue){
                             input.val(text).addClass("phcolor");
                         }
                         input.focus(function(){
                             if(input.val() == text){
                                 $(this).val("");
                             }
                         });
                         input.blur(function(){
                             if(input.val() == ""){
                                 $(this).val(text).addClass("phcolor");
                             }
                         });
                         //输入的字符不为灰色
                         input.keydown(function(){
                             $(this).removeClass("phcolor");
                         });
                     };
             //当浏览器不支持placeholder属性时，调用placeholder函数
             if(!supportPlaceholder){
                 $('input').each(function(){
                     text = $(this).attr("placeholder");
                     if($(this).attr("type") == "text"){
                         placeholder($(this));
                     }
                 });
             };
      });
    </script>
    
  </body>
</html>
